package presentation;

import java.awt.Adjustable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;

import javax.swing.*;

import communication.NetworkService;
import communication.impl.Receiver;
import communication.impl.Sender;

public class AdminConsole extends JFrame{
	
	private static final long serialVersionUID = 862960466847268055L;

    private JTable messagesTable;
    
    JScrollBar scrollBarVertical = new JScrollBar();
    JScrollBar scrollbarHorizontal = new JScrollBar(Adjustable.HORIZONTAL);
	AdminConsole() throws RemoteException, AlreadyBoundException {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(600, 400);
		this.setTitle("Console d'administration");
		
		scrollBarVertical.setPreferredSize(new Dimension(20, 200));
	    scrollbarHorizontal.setPreferredSize(new Dimension(200, 20));
	    
		this.setLayout(new GridLayout(0,1));
		
		String networkServiceBindingName =
				System.getProperty("protocole.callback.binding.name", 
						NetworkService.AdminNetworkServiceBindingName);
		int serverPort = Integer.parseInt(
			System.getProperty("protocole.callback.server.port", "33000"));
		int registryPort = Integer.parseInt(
				System.getProperty("protocole.callback.registry.port", "33001"));
	    Receiver receiver = new Receiver(
				registryPort, 
				serverPort, 
				networkServiceBindingName);
		
		messagesTable = new JTable(receiver.getTable());

		getContentPane().add(new JScrollPane(messagesTable));
		 
		 messagesTable.add(scrollBarVertical);
		 messagesTable.add(scrollbarHorizontal);
		
		setVisible(true);
		Sender decouvreRTDG = new Sender();
		decouvreRTDG.send();
	}
	
	public static void main(String args[]) throws RemoteException, AlreadyBoundException {
		new AdminConsole();
		
		
	}
}
